【已解决】Makefile中判断一个文件是否存在 – 在路上 |
您所在的位置:网站首页 › makefile 判断目录是否存在 › 【已解决】Makefile中判断一个文件是否存在 – 在路上 |
折腾: 【已解决】更新gitbook发布脚本Makefile忽略某些book 期间,需要去判断判断文件 deploy_ignore_book_crifan_com.txt 是否存在 然后再去执行不同动作。 makefile check file exist How do I check if file exists in Makefile so I can delete it? – Stack Overflow gnu – Testing if a file exists in makefile target, and quitting if not present – Stack Overflow 好像是这类: clean: if [ -d "${OUTDIR}" ]; then \ rm -r ${OUTDIR}; \ fi \Makefile – Check if a file exists using wildcard function – Humbug 然后去试试: ifneq [ -f $(DEPLOY_IGNORE_BOOK_CRIFAN_COM) ] ifneq [ -f "$(DEPLOY_IGNORE_BOOK_CRIFAN_COM)" ]都语法报错: 261: *** missing separator. Stop. if [ -f "$(DEPLOY_IGNORE_BOOK_CRIFAN_COM)" ] SHOULD_IGNORE = false endifif [ -f “$(DEPLOY_IGNORE_BOOK_CRIFAN_COM)” ] SHOULD_IGNORE = false fi 也都报语法错误 -》这个是shell的语法,不是Makefile的语法 去试试 DEPLOY_IGNORE_BOOK_CRIFAN_COM = deploy_ignore_book_crifan_com.txt ifneq ("$(wildcard $(DEPLOY_IGNORE_BOOK_CRIFAN_COM))", "") $(info $(DEPLOY_IGNORE_BOOK_CRIFAN_COM) is not empty) endif但是没有输出打印 How to check if a file exists in Makefile – Stack Overflow 试了半天只有文件的全路径,才可以: # DEPLOY_IGNORE_BOOK_CRIFAN_COM = deploy_ignore_book_crifan_com.txt # DEPLOY_IGNORE_BOOK_CRIFAN_COM = ./deploy_ignore_book_crifan_com.txt DEPLOY_IGNORE_BOOK_CRIFAN_COM = /Users/crifan/dev/dev_root/gitbook/gitbook_src_root/deploy_ignore_book_crifan_com.txt ifneq ("$(wildcard $(DEPLOY_IGNORE_BOOK_CRIFAN_COM))", "") $(info $(DEPLOY_IGNORE_BOOK_CRIFAN_COM) is not empty) endif才能输出: /Users/crifan/dev/dev_root/gitbook/gitbook_src_root/deploy_ignore_book_crifan_com.txt is not empty【总结】 DEPLOY_IGNORE_BOOK_CRIFAN_COM = $(GITBOOK_ROOT)/deploy_ignore_book_crifan_com.txt $(info DEPLOY_IGNORE_BOOK_CRIFAN_COM=$(DEPLOY_IGNORE_BOOK_CRIFAN_COM)) ifneq ("$(wildcard $(DEPLOY_IGNORE_BOOK_CRIFAN_COM))", "") $(info $(DEPLOY_IGNORE_BOOK_CRIFAN_COM) is not empty) endif可以检测出,对应文件(注意要绝对路径)的存在,然后输出: /Users/crifan/dev/dev_root/gitbook/gitbook_src_root/deploy_ignore_book_crifan_com.txt is not empty后记: 折腾了: 【已解决】Makefile中判断变量是否为空无效 后,其实发现也可以把 ifneq ("$(wildcard $(DEPLOY_IGNORE_BOOK_CRIFAN_COM))", "")写成: ifneq ($(wildcard $(DEPLOY_IGNORE_BOOK_CRIFAN_COM)), )即: 要么都有””,要么都不用”” 转载请注明:在路上 » 【已解决】Makefile中判断一个文件是否存在 Post Views: 3,975 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |